package com.plant.serviceImpl;

import com.plant.dao.BaseDao;
import com.plant.entity.UgcFollow;
import com.plant.entity.UgcFriends;
import com.plant.entity.UgcUser;
import com.plant.service.FollowUserService;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 */
@Service
@Transactional
public class FollowUserServiceImpl implements FollowUserService{

    @Resource(name = "baseDaoImpl")
    private BaseDao baseDao;

	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> LookFiveUserinf(Object ids,String level) {
		String sql="SELECT id user_id,nickname,photo FROM ugc_user where id not in ("+ids+") and `level`='"+level+"' ORDER BY rand() LIMIT 5";
		return baseDao.Bysql(sql, null);
	}

	public boolean AddFollowUser(UgcFollow ufo) {//添加关注用户
		return baseDao.add(ufo);
	}

	@SuppressWarnings("unchecked")
	public List<Object> GetFollowUserByApply(UgcUser user) {
		String hql="select receive_user_id from ugc_follow where apply_user_id=("+user.getId()+")";
		return baseDao.Bysql(hql, UgcUser.class);
	}

	
	@SuppressWarnings("unchecked")
	public List<Map<String, Object>> GetOfficialAccount(UgcUser user) {
        String sql="select id user_id,nickname,photo from ugc_user where id="+user.getId()+"";
		return baseDao.Bysql(sql, null);
	}

	public boolean AddOfficialAccountFriend(UgcFriends uf) {
		return baseDao.add(uf);
	}

	@SuppressWarnings("unchecked")
	public boolean CheckOfficalAccount(UgcFriends uf) {
		List<Object> list=new ArrayList<Object>();
		String hql="from UgcFriends where receiveUserId=("+uf.getReceiveUserId()+") and applyUserId=("+uf.getApplyUserId()+")";
		list=baseDao.find(hql);
		if(list.size()>0){
			return true;
		}else{
			return false;
		}
	}
}
